﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Husb.Data;
using Husb.Util;
using GroundWater.Data;
using GroundWater.DataAccess;
using AbnormalTable = GroundWater.Data.AbnormalDataSet.WaterlevelAbnormalDataTable;
using AbnormalRow = GroundWater.Data.AbnormalDataSet.WaterlevelAbnormalRow;


namespace GroundWater.BusinessActions
{
    public class WaterlevelAbnormal : DataAccessManager<AbnormalDataSet, AbnormalTable, AbnormalRow, WaterlevelAbnormalAdapter>
    {
        public static AbnormalRow FetchByMonitoringId(string wellCode, DateTime monitoringTime, decimal warningDifference)
        {
            WaterlevelAbnormalAdapter adapter = new WaterlevelAbnormalAdapter();
            return adapter.FetchByMonitoringId(wellCode, monitoringTime, warningDifference);
        }

        public static AbnormalTable FetchByTimeSpan(string startDate, string endDate, decimal warningDifference)
        {
            WaterlevelAbnormalAdapter adapter = new WaterlevelAbnormalAdapter();
            return adapter.FetchByTimeSpan(startDate, endDate, warningDifference);
        }


        public static AbnormalTable FetchPaged(string startDate, string endDate, string sortExpression, int maximumRows, int startRowIndex)
        {
            if (String.IsNullOrEmpty(startDate))
            {
                startDate = DateTime.Now.AddDays(-10).ToString("yyyy-MM-dd");
            }
            if (String.IsNullOrEmpty(endDate))
            {
                endDate = DateTime.Now.ToString("yyyy-MM-dd");
            }
            if (String.IsNullOrEmpty(sortExpression))
            {
                sortExpression = "ExamineDate DESC";
            }
            WaterlevelAbnormalAdapter adapter = new WaterlevelAbnormalAdapter();
            return adapter.FetchPaged(startDate, endDate, sortExpression, maximumRows, startRowIndex);
        }

        public static int FetchRowCount(string startDate, string endDate)
        {
            WaterlevelAbnormalAdapter adapter = new WaterlevelAbnormalAdapter();
            return adapter.FetchRowCount( startDate, endDate);
        }
    }
}
